﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using DiscoveryLogic.Common.Utilities;

namespace DiscoveryLogic.Analytics.DataObjects.Networks
{
    public class EntitySetProvider
    {
        #region props
        private SetDataProvider _SetProvider;
        /// <summary></summary>
        public SetDataProvider SetProvider
        {
            get
            {
                return this._SetProvider;
            }
            set
            {
                this._SetProvider = value;
            }
        }

        private EntityType _EntityType;
        /// <summary></summary>
        public EntityType EntityType
        {
            get
            {
                return this._EntityType;
            }
            set
            {
                this._EntityType = value;
            }
        }
        #endregion

        #region ctor
        public EntitySetProvider()
        {
            this._SetProvider=new SetDataProvider();
            this._EntityType = EntityType.Grants;
        }

        public EntitySetProvider(SetDataProvider provider, EntityType entityType)
        {
            this._SetProvider = provider;
            this._EntityType = entityType;
        }
        #endregion

        #region xml 
        public void Save(ref XmlDocument xDoc, XmlNode providerNode)
        {
            XmlDataUtil.UpdateAttribute(ref xDoc, providerNode, "EntityType",this.EntityType.ToString());
            this.SetProvider.Save(ref xDoc, providerNode);
        }

        public static EntitySetProvider Read(XmlNode setProviderNode)
        {
            EntitySetProvider setProvider=new EntitySetProvider();
            setProvider.EntityType =
                (EntityType) Enum.Parse(
                                 typeof (EntityType),
                                 XmlDataUtil.GetAttributeValue(
                                     setProviderNode, "EntityType", EntityType.Grants.ToString()));
            setProvider.SetProvider = SetDataProvider.Read(setProviderNode);
            return setProvider;
        }
        #endregion
    }
}
